/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.commonservice.common;

import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;

import java.io.File;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author lw
 * @ClassName: DbConfig
 * @date 2021年7月8日
 * @Description:全局配置
 */
public class DbConfig {
    static {
        Properties prop = new Properties();
        // 通过Object.class获取资源路径 path
        // 不以’/'开头时默认是从此类所在的包下取资源，以’/'开头则是从ClassPath根下获取。其只是通过path构造一个绝对路径，最终还是由ClassLoader获取资源。
        // InputStream in = Object.class.getResourceAsStream("/cas.properties");
        InputStream in = DbConfig.class.getClassLoader().getResourceAsStream("dbconfig.properties");
        try {
            prop.load(in);
            // 获取value
            IP = prop.getProperty("ip");
            CITY = prop.getProperty("city");
            COUNTY = prop.getProperty("county");
            DRAINAGEAREA = prop.getProperty("drainagearea");
            STATIONIDSK = prop.getProperty("stationidSK");
            STATIONIDYB = prop.getProperty("stationidYB");
            STATIONIDSOIL=prop.getProperty("stationidSoil");
            STATIONID = prop.getProperty("stationid");
            X = prop.getProperty("x");
            Y = prop.getProperty("y");
            RADARID = prop.getProperty("radarid");

            advCode = prop.getProperty("advCode");
            gridPath = prop.getProperty("gridPath");
            HFZ = prop.getProperty("hfz");
            HFZID = prop.getProperty("hfzid");
            ZFGC = prop.getProperty("zfgc");
            ZFGCID = prop.getProperty("zfgcid");
            QSYBQH = prop.getProperty("qsybqh");
            CACHEDAYS = Integer.parseInt(prop.getProperty("cachedays"));
            SMALLSCALE = prop.getProperty("smallscale");

            rd_host = prop.getProperty("rd_host");
            rd_port = prop.getProperty("rd_port");
            linuxpath = prop.getProperty("linuxpath");
            winpath = prop.getProperty("winpath");
            dbname = prop.getProperty("dbname");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String IP;

    public static String STATIONID;

    public static String X;

    public static String Y;
    public static String RADARID;

    public static String DRAINAGEAREA;
    public static String CITY;
    public static String COUNTY;
    public static String STATIONIDSK;
    public static String STATIONIDYB;
    public static String STATIONIDSOIL;
    /**
     * 小站代替大站 名称   湘潭-岳塘区
     */
    public static String HFZ;
    /**
     * 小站代替大站 编号
     */
    public static String HFZID;
    /**
     * 小站代替大站 名称   湘潭-雨湖区
     */
    public static String ZFGC;
    /**
     * 小站代替大站 编号
     */
    public static String ZFGCID;
    /**
     * 潜势预报
     */
    public static String QSYBQH;
    /**
     * 数据缓存天数
     */
    public static Integer CACHEDAYS;// = 30;
    public static String SMALLSCALE;

    public static String advCode;

    //redis ip和端口
    public static String rd_host;

    public static String rd_port;

    public static String gridPath;
    public  static  String winpath;
    public  static String linuxpath;
    public  static String dbname;

    public static String getRaderType(String ldtype) {
        String type = "";
        switch (ldtype) {
            case "19":
                type = "基本反射率图19";
                break;
            case "20":
                type = "基本反射率图20";
                break;
            case "26":
                type = "基本速度26";
                break;
            case "27":
                type = "基本速度27";
                break;
            case "CR37":
                type = "组合反射率图37";
                break;
            case "38":
                type = "组合反射率图38";
                break;
            default:
                break;
        }
        return type;
    }

    public static String getRadarFileName(String ldtype, String elevation, String stationId, Date datechar,
                                          String timechar) {
        if (elevation.equals("0.5"))
            elevation = "01";
        else if (elevation.equals("1.5"))
            elevation = "02";
        else if (elevation.equals("2.4"))
            elevation = "03";
        else if (elevation.equals("3.4"))
            elevation = "04";
        else if (elevation.equals("4.3"))
            elevation = "05";
        else if (elevation.equals("6.0"))
            elevation = "06";
        else if (elevation.equals("9.9"))
            elevation = "07";
        else if (elevation.equals("14.6"))
            elevation = "08";
        else if (elevation.equals("19.5"))
            elevation = "09";
        else
            elevation = "000";
        return new DateTime(datechar).toDateTimeString("yyyyMMdd") + "." + timechar + "." + elevation + "." + ldtype
                + "." + stationId;
    }

    public static String getYtFileName(String yttype, Date datechar, String timechar) {
        String subdir = "";
        String filename = "";
        String channel = "R01";
        switch (yttype) {
            case "FY2E红外图像":
                subdir = "IR1";
                break;
            case "FY2E分裂窗图像":
                subdir = "IR2";
                break;
            case "FY2E水汽图像":
                subdir = "IR3";
                break;
            case "FY2E中红外图像":
                subdir = "IR4";
                break;
            case "FY2E可见光图像":
                subdir = "VIS";
                channel = "R03";
                break;
            default:
                break;
        }
        filename = String.format("ANI_%s_%s_%s_%s_FY2E.AWX", subdir, channel,
                new DateTime(datechar).toDateTimeString("yyyyMMdd"), timechar);
        return filename;
    }

    public static String getYt3AFileName(String yttype, Date datechar, String timechar) {
        String subdir = "";
        String filename = "";
        String channel = "R01";
        switch (yttype) {
            case "FY3A红外图像":
                subdir = "IR1";
                break;
            case "FY3A分裂窗图像":
                subdir = "IR2";
                break;
            case "FY3A水汽图像":
                subdir = "IR3";
                break;
            case "FY3A中红外图像":
                subdir = "IR4";
                break;
            case "FY3A可见光图像":
                subdir = "VIS";
                channel = "R03";
                break;
            default:
                break;
        }
        filename = String.format("ANI_%s_%s_%s_%s_FY3A.AWX", subdir, channel,
                new DateTime(datechar).toDateTimeString("yyyyMMdd"), timechar);
        return filename;
    }

    public static Map<String, String> getZhiShuType() {
        Map<String, String> zs = new HashMap<String, String>();
        zs.put("zz", "着装气象指数");
        zs.put("zw", "紫外线指数");
        zs.put("ys", "雨伞指数");
        zs.put("lyou", "旅游气象指数");
        zs.put("jt", "交通气象指数");
        zs.put("cl", "晨练气象指数");
        zs.put("wr", "空气污染气象条件");
        return zs;
    }

    public static String getRaderMosaicType(String ldtype) {
        String type = "";
        switch (ldtype) {
            case "r":
                type = "基本反射率";
                break;
            case "cr":
                type = "组合反射率";
                break;
            case "vil":
                type = "垂直累积液态水含量";
                break;
            default:
                break;
        }
        return type;
    }

    public static String getRadarMosaicFileName(String ldtype, Date datechar, String timechar) {
        return new DateTime(datechar).toDateTimeString("yyyyMMdd") + "." + timechar + "." + ldtype;
    }
}